package setup;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

import common.PasswordStore;

import server.Journal;
import server.Patient;
import server.Storage;
import server.User;

public class GenerateStorageFile {

	public static void main(String[] args) {
		PasswordStore pws = new PasswordStore();
		pws.add("doctor1", "password");
		pws.add("nurse1", "password");
		pws.add("doctor2", "password");
		pws.add("nurse2", "password");
		pws.add("agentsmith", "password");
		pws.add("sebastian", "password");
		pws.add("hawoay", "password");
		pws.add("arvid", "password");
		pws.add("anders", "password");
		
		Storage s = new Storage();
		
		ArrayList<User> users = new ArrayList<User>();
		users.add(new User("sebastian", User.PATIENT, ""));
		users.add(new User("hawoay", User.PATIENT, ""));
		users.add(new User("arvid", User.PATIENT, ""));
		users.add(new User("anders", User.PATIENT, ""));
		
		users.add(new User("nurse1", User.NURSE, "hand_division"));
		users.add(new User("nurse2", User.NURSE, "nose_division"));
		users.add(new User("doctor1", User.DOCTOR, "hand_division"));
		users.add(new User("doctor2", User.DOCTOR, "nose_division"));
		users.add(new User("agentsmith", User.GOVT, ""));
		
		ArrayList<Patient> p = new ArrayList<Patient>();
		Patient p1 = new Patient("sebastian");
		p1.associateWith("nurse1");
		p1.associateWith("doctor1");
		Patient p2 = new Patient("hawoay");
		p2.associateWith("nurse2");
		p1.associateWith("doctor2");
		Patient p3 = new Patient("arvid");
		p3.associateWith("nurse1");
		p1.associateWith("doctor2");
		Patient p4 = new Patient("anders");
		p4.associateWith("nurse2");
		p1.associateWith("doctor1");
		p.add(p1);
		p.add(p2);
		p.add(p3);
		p.add(p4);
		
		ArrayList<Journal> j = new ArrayList<Journal>();
		Journal j1 = new Journal("big_hands", p1, "hand_division", "Hands are freakishly big. Scheduled surgery for 4/20.");
		Journal j2 = new Journal("broken_nose", p2, "nose_division", "Advice patient not to engage in drunken bar fights.");
		Journal j3 = new Journal("hairy_hands", p3, "hand_division", "Hair growing on both palms. Excess masturbation suspected.");
		Journal j4 = new Journal("no_hands", p4, "hand_division", "Hands seem to have gone missing during routine checkup.");
		j1.associateWith("nurse2");
		j2.associateWith("nurse2");
		j3.associateWith("nurse1");
		j4.associateWith("nurse2");
		j1.associateWith("doctor1");
		j2.associateWith("doctor1");
		j3.associateWith("doctor1");
		j4.associateWith("doctor2");
		j.add(j1);
		j.add(j2);
		j.add(j3);
		j.add(j4);
		
		s.patients = p;
		s.journals = j;
		s.users = users;
		s.pws = pws;
		
		try{
			// Write to disk with FileOutputStream
			FileOutputStream f_out = new 
				FileOutputStream("storage");
	
			// Write object with ObjectOutputStream
			ObjectOutputStream obj_out = new
				ObjectOutputStream (f_out);
	
			// Write object out to disk
			obj_out.writeObject (s);
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
